package LeetCode_Section;

//寻找中间节点
public class FindMiddleNode {
    public class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next;
    }
 }

    class Solution {
        public ListNode middleNode(ListNode head) {
            int count = 0;
            ListNode cur = head;
            while (cur != null) {
                ++count;
                cur = cur.next;
            }

            int num = 0;
            cur = head;

            while (num < count / 2) {
                ++num;
                cur = cur.next;
            }
            return cur;
        }
    }
}
